{{define "cms/log_list.html"}}
{{ template "header" . }}

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="ibox-title">
            权限管理 / 日志记录
        </div>
        <div role="form" class="form-inline">
            <div class="ibox-title">
                <div class="form-group">
                    <label for="name" class="sr-only">用户名</label>
                    <input type="text" name="searchName" placeholder="请输入用户名" class="form-control" value="{{ .searchName }}">
                </div>
                <button class="btn btn-white" onclick="search()"><i class="fa fa-search"></i> 搜索</button>
            </div>
        <div class="row">
            <div class="col-sm-12">
                <input type="hidden" name="token" value="{{ .token }}">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <button class="btn btn-xs btn-info" onclick="checkAll(true)">全选</button>
                        <button class="btn btn-xs btn-info" onclick="checkAll(false)">全不选</button>
                        <button class="btn btn-xs btn-info" onclick="checkReverse()">反选</button>
                        <button class="btn btn-xs btn-warning" onclick="delete_check()">删除</button>
                        <div class="table-responsive">
                            <table class="table">
                                <thead>
                                    <tr>
                                        <th></th>
                                        <th>ID</th>
                                        <th>用户名</th>
                                        <th>操作</th>
                                        <th>路径</th>
                                        <th>请求方法</th>
                                        <th>创建时间</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {{range .lists}}
                                    <tr>
                                        <td>
                                            <input type="checkbox" name="input[]" value="{{.ID}}" aria-label="">
                                        </td>
                                        <td>{{.ID}}</td>
                                        <td>{{.UserName}}</td>
                                        <td>{{.Option}}</td>
                                        <td>{{.Path}}</td>
                                        <td>{{.Method}}</td>
                                        <td>{{.CreatedAt}}</td>
                                    </tr>
                                    {{end}}

                                </tbody>
                            </table>
                        </div>
                        <div class="paginate">
                            <ul>
                                {{ if gt .page 1 }}
                                    <li><a href="/logrecord?page=1&pageSize={{.pageSize}}&searchName={{ .searchName }}">首页</a></li>
                                    <li><a href="/logrecord?page={{ .prePage }}&pageSize={{.pageSize}}&searchName={{ .searchName }}">上一页</a></li>
                                    <li><a href="/logrecord?page={{ .prePage }}&pageSize={{.pageSize}}&searchName={{ .searchName }}">{{ .prePage }}</a></li>
                                {{ else }}
                                    <li>首页</li>
                                    <li><span>上一页</span></li>
                                {{ end }}


                                <li class="curr-page"><a href="/logrecord?page={{ .page }}&pageSize={{.pageSize}}&searchName={{ .searchName }}">{{ .page }}</a></li>

                                {{ if lt .page .total }}
                                    <li><a href="/logrecord?page={{ .nextPage }}&pageSize={{.pageSize}}&searchName={{ .searchName }}">{{ .nextPage }}</a></li>
                                    <li><a href="/logrecord?page={{ .nextPage }}&pageSize={{.pageSize}}&searchName={{ .searchName }}">下一页</a></li>
                                    <li><a href="/logrecord?page={{ .total }}&pageSize={{.pageSize}}&searchName={{ .searchName }}">尾页</a></li>
                                {{ else }}
                                    <li><span>下一页</span></li>
                                    <li><span>尾页</span></li>
                                {{ end }}
                                <li class="project_page">
                                    <select aria-label="" class="page-form-control limit" name="pageSize" id="setPageSize">
                                        <option value="10" {{ if eq .pageSize 10 }} selected{{end}}>10条/页</option>
                                        <option value="20" {{ if eq .pageSize 20 }} selected{{end}}>20条/页</option>
                                        <option value="30" {{ if eq .pageSize 30 }} selected{{end}}>30条/页</option>
                                        <option value="40" {{ if eq .pageSize 40 }} selected{{end}}>40条/页</option>
                                        <option value="50" {{ if eq .pageSize 50 }} selected{{end}}>50条/页</option>
                                    </select>
                                </li>
                                <li><span>共{{ .total }}页</span></li>
                                <li>
                                    <input name="page_href" class="page-form-control-input" value="{{.page}}" aria-label=""> 页
                                </li>
                                <li>
                                    <button class="btn btn-primary btn-xs hrefTo" onclick="href_to()">
                                        <i class="fa fa-location-arrow"></i> 跳转
                                    </button>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
          </div>
        </div>
    </div>
</body>

{{ template "footer" . }}
<script>
    $("#setPageSize").on('change', function(){
        var size = $("#setPageSize option:selected").val();
        window.location.href = "/logrecord?page={{ .page }}&pageSize=" + size + "&searchName={{ .searchName }}";
    });

    function checkAll(ok){
        var checkboxs = $("input[name='input[]']");
        if (ok){
            checkboxs.each(function(){
                $(this).prop("checked",true)
            })
        }else {
            checkboxs.each(function(){
                $(this).prop("checked",false)
            })
        }
    }

    function checkReverse() {
        var checkboxs = $("input[name='input[]']");
        checkboxs.each(function(){
            this.checked = !this.checked
        })
    }

    function search() {
        var name = $("input[name='searchName']").val();
        window.location.href = "/logrecord?page={{ .page }}&pageSize={{.pageSize}}&searchName=" + name;
    }

    function href_to() {
        var page = $("input[name='page_href']").val();
        window.location.href = "/logrecord?page=" + page + "&pageSize={{.pageSize}}&searchName={{ .searchName }}";
    }

    function delete_check(){
        var ids = Array();
        var checkboxs = $("input[name='input[]']");
        checkboxs.each(function(){
            if (this.checked) {
                ids.push(parseInt(this.value));
            }
        });
        if (ids.length === 0){
            layer.msg("请勾选需要删除的选项", {icon: 2, time: 1200, title: "提示"});
            return;
        }

        layer.confirm("确定删除?", {
            btn: ['确定','取消']
        }, function() {
            var token = $("input[name='token']").val();
            var url = "/logrecord?page={{ .page }}&pageSize={{.pageSize}}&searchName={{.searchName}}";
            jQuery.ajaxSettings.traditional = true;
            $.post("/logrecorddel", {ids:ids, token: token, url:url},function (res) {
                var jsonData = $.parseJSON(res);
                if(jsonData.status !== 200 && jsonData.status !== 20023){
                    if(jsonData.status !== 20007) {
                        $("input[name='token']").val(jsonData.data);
                    }
                    layer.msg(jsonData.message, {icon: 2, time: 1200, title: "提示"});
                } else if(jsonData.status === 20023) {
                    window.location.href = "/nopermission";
                } else {
                    layer.msg(jsonData.message, {
                        icon: 1,
                        time: 1000,
                        title: "提示",
                        end:function () {
                            window.location.href = jsonData.data;
                        }
                    });
                }
            });
        });
    }
</script>
{{end}}